package com.dq.demo.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dq.demo.config.AppDataSourse;
import com.dq.wallpaper.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Author:ZJC
 * Date:2020/2/7  16:01
 * Description:UserServiceAgreementActivity
 */
public class UserServiceAgreementActivity extends BaseActivity {

    public static final String TYPE = "type";
    @BindView(R.id.title)
    public RelativeLayout rlTitle;
    @BindView(R.id.tv_title)
    public TextView tvTitle;
    @BindView(R.id.img_back)
    public ImageView imgBack;
    @BindView(R.id.webview)
    public WebView webView;
    @BindView(R.id.img_title)
    ImageView imgTitle;

    public static void startAct(Activity activity, int type) {
        Intent intent = new Intent(activity, UserServiceAgreementActivity.class);
        intent.putExtra(TYPE, type);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_service_agreement);
        ButterKnife.bind(this);
        initView();
        initData();
    }

    @Override
    public void initView() {
        rlTitle.setPadding(0, height, 0, 0);
        int type = getIntent().getIntExtra(TYPE, 0);
        WebSettings settings = webView.getSettings();
        // 设置缩放
        settings.setBuiltInZoomControls(false);
        // 使页面适应用户屏幕
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        // 开启JavaScript
        settings.setJavaScriptEnabled(true);
        webView.setVerticalScrollBarEnabled(false);//隐藏垂直滚动条
        if (type == 0) {//用户协议
            tvTitle.setText("用户协议");
            webView.loadUrl(AppDataSourse.getAssetsUser);
        } else if (type == 1) {//隐私协议
            tvTitle.setText("隐私政策");
            webView.loadUrl(AppDataSourse.getAssetsPrivacy);
        }
    }

    @Override
    public void initData() {

    }

    @OnClick(R.id.img_back)
    public void onViewClicked() {
        finish();
    }
}